package com.danielepelagatti.flickrmanager.commands.photo
{
	import com.adobe.webapis.flickr.Photo;
	import com.adobe.webapis.flickr.events.FlickrResultEvent;
	import com.danielepelagatti.flickrmanager.commands.CommandHelper;
	import com.danielepelagatti.flickrmanager.commands.FlickrCommand;
	import com.danielepelagatti.flickrmanager.commands.IFlickrCommand;
	import com.danielepelagatti.flickrmanager.model.Flickr;
	import com.danielepelagatti.flickrmanager.model.LocalUser;
	import com.theriabook.utils.Logger;
	/**
	 * 
	 * @author redde
	 * 
	 */
	public class Delete extends FlickrCommand implements IFlickrCommand
	{
		/**
		 * 
		 * @param event
		 * 
		 */		
		public function error(event:FlickrResultEvent):Boolean
		{
			return false;
		}
		/**
		 * 
		 * @param event
		 * 
		 */		
		public function success(event:FlickrResultEvent):void
		{
			var pending:Photo = CommandHelper.getPhotoForOperation(event.type,Photo(event.data.photo).id)
			if(pending)
			{
				LocalUser.getInstance().photoCollection.removePhotoById(pending.id);
				CommandHelper.removePhotoOperation(event.type,pending);
			}
			else
				Logger.error("Delete:: photo "+event.data.photo.id+" cannot be deleted from the local model");
		}
		/**
		 * 
		 * @return 
		 * 
		 */		
		public function getAPICall():Function
		{
			return flickr.photos.remove;
		}
		
	}
}